package com.example.app.pages.main.home.addNew.addRecord.MyModalBottomSheetRelationPicker

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.example.app.components.MyDialog.MyfullScreenDialogState
import com.example.app.components.MyNotify.MyNotifyType
import com.example.app.data.bean.routeAddAccount.AccountRelationPeople
import com.example.app.pages.main.home.me.viewModel.AddNewViewModel
import com.example.app.viewmodel.MainViewModel

enum class ManageRelationCurShowPage(
        var pageName: String
) {
    MANAGE_RELATION_LIST("ManageRelationList"),
    EDIT_RELATION("EditRelation"),
    ADD_RELATION("AddRelation"),
}
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun ManageRelation(

        animateOffsetX: Dp,
        fullScreenDialogState: MyfullScreenDialogState,

) {
    var windowWidth = with(LocalDensity.current) {
        LocalConfiguration.current.screenWidthDp
    }.dp
    var curSelectedRelationPeople by remember {
        mutableStateOf<AccountRelationPeople?>(null)
    }
    //当前显示
    var curShowPage by remember {
        mutableStateOf(ManageRelationCurShowPage.MANAGE_RELATION_LIST)
    }
    var scope = rememberCoroutineScope()
    var notifyShow = remember {
        mutableStateOf(false)
    }
    var notifyType = remember {
        mutableStateOf(MyNotifyType.SUCCESS)
    }
    var notifyContent = remember {
        mutableStateOf("")
    }

    Box(modifier = Modifier.fillMaxSize()) {
        when (curShowPage) {
            //关系人列表
            ManageRelationCurShowPage.MANAGE_RELATION_LIST -> {
                ManageRelationList(
                    notifyShow = notifyShow,
                    notifyType = notifyType,
                    notifyContent = notifyContent,

                    animateOffsetX = animateOffsetX,
                    windowWidth = windowWidth,
                    //退出
                    dismiss = {
                        curShowPage = ManageRelationCurShowPage.MANAGE_RELATION_LIST
                        curSelectedRelationPeople = null
                        fullScreenDialogState.flowUpdate_visible(false)
                    },
                    //新增关系
                    addRelationPeopleHandler = {
                        curShowPage = ManageRelationCurShowPage.ADD_RELATION
                    },
                    editSelectedCurRelationPeopleHandler = {
                        curSelectedRelationPeople = it
                        curShowPage = ManageRelationCurShowPage.EDIT_RELATION
                    }
                )
            }
            //修改关系人
            ManageRelationCurShowPage.EDIT_RELATION -> {
                EditRelation(
                    curRelationPeople = curSelectedRelationPeople!!,

                    animateOffsetX = animateOffsetX,

                    dismiss = {
                        curShowPage = ManageRelationCurShowPage.MANAGE_RELATION_LIST
                    },
                    editFinishHandler = {
                        notifyContent.value = "修改成功"
                        notifyShow.value = true
                    }
                )
            }
            //新增关系人
            ManageRelationCurShowPage.ADD_RELATION -> {
                AddRelation(
                    animateOffsetX = animateOffsetX,
                    fullScreenDialogState = fullScreenDialogState,

                    dismiss = {
                        curShowPage = ManageRelationCurShowPage.MANAGE_RELATION_LIST
                    }
                )
            }

            else -> {
            }
        }
    }
}

